package com.buybuyyi.stylistcrm.resource.controllers.order;

import com.buybuyyi.stylistcrm.resource.controllers.DefaultController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import stylistcrm.core.query.ResultPagerModel;
import stylistcrm.core.services.order.dto.OrderGoodsDto;
import stylistcrm.core.services.order.dto.PurchaseOrderDto;
import stylistcrm.core.services.order.dto.QueryOrderConditionDto;
import stylistcrm.core.services.order.dto.UserOrderDto;
import stylistcrm.core.services.order.enums.EnumExceptionCode;
import stylistcrm.core.services.order.exception.BizException;
import stylistcrm.core.services.order.service.PurchaseOrderService;
import stylistcrm.core.services.order.service.UserOrderService;

import java.util.List;

/**
 * Created by cheny on 2016/9/5.
 */
@Controller
@RequestMapping("/order")
public class UserOrderController extends DefaultController{

    @Autowired
    private UserOrderService userOrderService;

    @ResponseBody
    @RequestMapping("/createuserorder")
    public Boolean createUsereOrder(UserOrderDto userOrderDto) throws BizException {
        super.checkLogin();
        if(null==userOrderDto){
            throw new BizException(EnumExceptionCode.EC0001);
        }
        Boolean saveFlag=userOrderService.createUserOrder(userOrderDto);
        return saveFlag;
    }
    @ResponseBody
    @RequestMapping("/getuserorderpagelist")
    public ResultPagerModel<UserOrderDto> getPurchaseOrderPageList(QueryOrderConditionDto queryCondition) throws BizException {
        Long userId=super.checkLogin();
        if(null==queryCondition){
            throw new BizException(EnumExceptionCode.EC0001);
        }
        queryCondition.setStylistId(userId.intValue());
        return userOrderService.getPageList(queryCondition);
    }
    @ResponseBody
    @RequestMapping("/getuserorderdetail")
    public UserOrderDto getPurchaseOrderDetail(Integer orderId) throws BizException {
        super.checkLogin();
        if(null==orderId){
            throw new BizException(EnumExceptionCode.EC0001);
        }
        return userOrderService.selectByPrimaryKey(orderId);
    }
}
